package com.agileboot.domain.medicine.model;

import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.domain.medicine.db.Medicine;
import com.agileboot.domain.medicine.db.MedicineService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 草药模型工厂
 * @author lx
 */
@Component
@RequiredArgsConstructor
public class MedicineModelFactory {
    private final MedicineService medicineService;

    public MedicineModel loadById(Long medicineId) {
        Medicine byId = medicineService.getById(medicineId);
        if (byId == null) {
            throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, medicineId, "草药");
        }
        return new MedicineModel(byId,medicineService);
    }

    public MedicineModel create() {
        return new MedicineModel(medicineService);
    }
}
